//
// Created by 先通明 on 2018/8/18.
//
#include <stdio.h>
#include "mylib.h"


char *s_gets(char *st, int n) {
    char *ret_val;
    ret_val = fgets(st, n, stdin);
    if (ret_val) {
        while (*st != '\n' && *st != '\0') {
            ++st;
        }
        if (*st == '\n') {
            *st = '\0';
        } else
            while (getchar() != '\n')
                continue;
    }
    return ret_val;
}

char *fs_gets(char *st, int n,FILE* file) {
    char *ret_val;
    ret_val = fgets(st, n, file);
    if (ret_val) {
        while (*st != '\n' && *st != '\0') {
            ++st;
        }
        if (*st == '\n') {
            *st = '\0';
        } else
            while (getchar() != '\n')
                continue;
    }
    return ret_val;
}

void eatline() {
    while (getchar() != '\n')
        continue;/* clear input line  */
}

int get_i() {
    int i;
    int s = scanf("%d", &i);
    eatline();
    if (s != 1)return 0;
    return i;
}
unsigned long get_ul() {
    unsigned long i;
    int s = scanf("%ld", &i);
    eatline();
    if (s != 1)return 0;
    return i;
}

int get_range_i(int min, int max) {
    int i;
    for (i = get_i(); i < min || i > max; i = get_i()) {
        printf("只能输入%d-%d:", min, max);
    }
    return i;
}

unsigned long get_range_ul(unsigned long min, unsigned long max) {
    unsigned long i;
    for (i = get_ul(); i < min || i > max; i = get_ul()) {
        printf("只能输入%ld-%ld:", min, max);
    }
    return i;
}


